package org.ianaz.chessfx.logic;

import java.util.ArrayList;

/**
 *
 * @author s.rainoldi
 */
public class Knight extends Figure {

    public Knight(Player player, Cell cell, int posX, int posY) {
        super(player, cell, posX, posY);
    }

    @Override
    public boolean[][] getPossibleMoves() {
        try {
            allowedMoves[getPosX() + 2][getPosY() + 1] = true;
        } catch (Exception e) {
        }
        try {
            allowedMoves[getPosX() + 2][getPosY() - 1] = true;
        } catch (Exception e) {
        }
        try {
            allowedMoves[getPosX() + 1][getPosY() + 2] = true;
        } catch (Exception e) {
        }
        try {
            allowedMoves[getPosX() - 2][getPosY() - 1] = true;
        } catch (Exception e) {
        }
        try {
            allowedMoves[getPosX() - 2][getPosY() + 1] = true;
        } catch (Exception e) {
        }
        try {
            allowedMoves[getPosX() - 1][getPosY() - 2] = true;
        } catch (Exception e) {
        }
        try {
            allowedMoves[getPosX() + 1][getPosY() - 2] = true;
        } catch (Exception e) {
        }
        try {
            allowedMoves[getPosX() - 1][getPosY() + 2] = true;
        } catch (Exception e) {
        }
        Cell[][] cells = getCell().getGame().getCells();
        for (int i = 0; i < allowedMoves.length; i++) {
            for (int l = 0; l < allowedMoves[i].length; l++) {
                if (allowedMoves[i][l] == true) {
                    // It is an allowed move
                    Figure fg = cells[i][l].getFigure();
                    if (fg != null) {
                        // There is a cell with a figure on it
                        if(fg.getPlayer().getColorString().equals(getPlayer().getColorString())){
                            // This is one of mine Figure on this cell, you don't want to eat it don't you?
                            allowedMoves[i][l] = false;
                        }
                    }
                }
            }
        }
        return allowedMoves;
    }
}
